import React from 'react';
import { Router, Switch, Route } from 'dva/router';
import _ from 'lodash';
import { Home, About } from '../pages';

const routes = [
  {
    name: 'home',
    path: '/home',
    // 如果不能正常显示子路由页面，需要将父路由 exact 改为 false
    exact: true,
    component: Home,
  },
  {
    name: 'about',
    path: '/about',
    exact: true,
    component: About,
  },
]

export default function RouteConfig({ history }){
  return (<Router history={history}>
    <Switch>
      {_.map(routes, (routeConfig) => {
        return (<Route {...routeConfig} key={_.get(routeConfig, 'name')} />);
      })}
    </Switch>
  </Router>);
}